package i18ns

import (
	"strings"
)

// LangInfo 语言信息结构体：包含英文名称、中文名称、母语名称
type LangInfo struct {
	EnglishName string // 英文名称
	ChineseName string // 中文名称
	NativeName  string // 母语名称
}

// langCodeMap 语言码 → 完整语言信息（新增50+语言，覆盖更多场景）
var langCodeMap = map[string]LangInfo{
	// 原有核心语言（补充中文名称）
	"af":     {"Afrikaans", "南非荷兰语", "Afrikaans"},
	"am":     {"Amharic", "阿姆哈拉语", "አማርኛ"},
	"ar":     {"Arabic", "阿拉伯语", "العربية"},
	"ar-AE":  {"Arabic (UAE)", "阿拉伯语（阿联酋）", "العربية (الإمارات العربية المتحدة)"},
	"ar-SA":  {"Arabic (Saudi Arabia)", "阿拉伯语（沙特）", "العربية (المملكة العربية السعودية)"},
	"az":     {"Azerbaijani", "阿塞拜疆语", "Azərbaycan dili"},
	"be":     {"Belarusian", "白俄罗斯语", "Беларуская"},
	"bg":     {"Bulgarian", "保加利亚语", "Български"},
	"bh":     {"Bihari", "比哈尔语", "भिहारी"},
	"bn":     {"Bengali", "孟加拉语", "বাংলা"},
	"br":     {"Breton", "布列塔尼语", "Brezhoneg"},
	"bs":     {"Bosnian", "波斯尼亚语", "Bosanski"},
	"ca":     {"Catalan", "加泰罗尼亚语", "Català"},
	"co":     {"Corsican", "科西嘉语", "Corsu"},
	"cs":     {"Czech", "捷克语", "Čeština"},
	"cy":     {"Welsh", "威尔士语", "Cymraeg"},
	"da":     {"Danish", "丹麦语", "Dansk"},
	"de":     {"German", "德语", "Deutsch"},
	"de-AT":  {"German (Austria)", "德语（奥地利）", "Deutsch (Österreich)"},
	"de-CH":  {"German (Switzerland)", "德语（瑞士）", "Deutsch (Schweiz)"},
	"de-DE":  {"German (Germany)", "德语（德国）", "Deutsch (Deutschland)"},
	"el":     {"Greek", "希腊语", "Ελληνικά"},
	"en":     {"English", "英语", "English"},
	"en-AU":  {"English (Australia)", "英语（澳大利亚）", "English (Australia)"},
	"en-CA":  {"English (Canada)", "英语（加拿大）", "English (Canada)"},
	"en-GB":  {"English (UK)", "英语（英国）", "English (UK)"},
	"en-NZ":  {"English (New Zealand)", "英语（新西兰）", "English (New Zealand)"},
	"en-US":  {"English (US)", "英语（美国）", "English (US)"},
	"en-ZA":  {"English (South Africa)", "英语（南非）", "English (South Africa)"},
	"eo":     {"Esperanto", "世界语", "Esperanto"},
	"es":     {"Spanish", "西班牙语", "Español"},
	"es-419": {"Spanish (Latin America)", "西班牙语（拉丁美洲）", "Español (América Latina)"},
	"es-ES":  {"Spanish (Spain)", "西班牙语（西班牙）", "Español (España)"},
	"et":     {"Estonian", "爱沙尼亚语", "Eesti"},
	"eu":     {"Basque", "巴斯克语", "Euskara"},
	"fa":     {"Persian", "波斯语", "فارسی"},
	"fa-IR":  {"Persian (Iran)", "波斯语（伊朗）", "فارسی (ایران)"},
	"fi":     {"Finnish", "芬兰语", "Suomi"},
	"fil":    {"Filipino", "菲律宾语", "Filipino"},
	"fo":     {"Faroese", "法罗语", "Føroyskt"},
	"fr":     {"French", "法语", "Français"},
	"fr-CA":  {"French (Canada)", "法语（加拿大）", "Français (Canada)"},
	"fr-CH":  {"French (Switzerland)", "法语（瑞士）", "Français (Suisse)"},
	"fr-FR":  {"French (France)", "法语（法国）", "Français (France)"},
	"fy":     {"Frisian", "弗里斯兰语", "Frysk"},
	"ga":     {"Irish", "爱尔兰语", "Gaeilge"},
	"gd":     {"Scots Gaelic", "苏格兰盖尔语", "Gàidhlig"},
	"gl":     {"Galician", "加利西亚语", "Galego"},
	"gn":     {"Guarani", "瓜拉尼语", "Guaraní"},
	"gu":     {"Gujarati", "古吉拉特语", "ગુજરાતી"},
	"ha":     {"Hausa", "豪萨语", "Hausa"},
	"haw":    {"Hawaiian", "夏威夷语", "Hawaiʻi"},
	"he":     {"Hebrew", "希伯来语", "עברית"},
	"hi":     {"Hindi", "印地语", "हिन्दी"},
	"hr":     {"Croatian", "克罗地亚语", "Hrvatski"},
	"hu":     {"Hungarian", "匈牙利语", "Magyar"},
	"hy":     {"Armenian", "亚美尼亚语", "Հայերեն"},
	"ia":     {"Interlingua", "国际语", "Interlingua"},
	"id":     {"Indonesian", "印度尼西亚语", "Bahasa Indonesia"},
	"is":     {"Icelandic", "冰岛语", "Íslenska"},
	"it":     {"Italian", "意大利语", "Italiano"},
	"it-CH":  {"Italian (Switzerland)", "意大利语（瑞士）", "Italiano (Svizzera)"},
	"it-IT":  {"Italian (Italy)", "意大利语（意大利）", "Italiano (Italia)"},
	"ja":     {"Japanese", "日语", "日本語"},
	"jw":     {"Javanese", "爪哇语", "Basa Jawa"},
	"ka":     {"Georgian", "格鲁吉亚语", "ქართული"},
	"kk":     {"Kazakh", "哈萨克语", "Қазақша"},
	"km":     {"Cambodian", "柬埔寨语（高棉语）", "ភាសាខ្មែរ"},
	"kn":     {"Kannada", "卡纳达语", "ಕನ್ನಡ"},
	"ko":     {"Korean", "韩语", "한국어"},
	"ko-KR":  {"Korean (South Korea)", "韩语（韩国）", "한국어 (대한민국)"},
	"ku":     {"Kurdish", "库尔德语", "Kurdî"},
	"ky":     {"Kyrgyz", "吉尔吉斯语", "Кыргызча"},
	"la":     {"Latin", "拉丁语", "Lingua Latina"},
	"ln":     {"Lingala", "林加拉语", "Lingála"},
	"lo":     {"Laothian", "老挝语", "ລາວ"},
	"lt":     {"Lithuanian", "立陶宛语", "Lietuviškai"},
	"lv":     {"Latvian", "拉脱维亚语", "Latviešu"},
	"mk":     {"Macedonian", "马其顿语", "Македонски"},
	"ml":     {"Malayalam", "马拉雅拉姆语", "മലയാളം"},
	"mn":     {"Mongolian", "蒙古语", "Монгол"},
	"mo":     {"Moldavian", "摩尔达维亚语", "Молдовеняскэ"},
	"mr":     {"Marathi", "马拉地语", "मराठी"},
	"ms":     {"Malay", "马来语", "Bahasa Melayu"},
	"ms-MY":  {"Malay (Malaysia)", "马来语（马来西亚）", "Bahasa Melayu (Malaysia)"},
	"mt":     {"Maltese", "马耳他语", "Malti"},
	"nb":     {"Norwegian (Bokmal)", "挪威语（博克马尔）", "Norsk bokmål"},
	"ne":     {"Nepali", "尼泊尔语", "नेपाली"},
	"nl":     {"Dutch", "荷兰语", "Nederlands"},
	"nl-NL":  {"Dutch (Netherlands)", "荷兰语（荷兰）", "Nederlands (Nederland)"},
	"nn":     {"Norwegian (Nynorsk)", "挪威语（新挪威）", "Norsk nynorsk"},
	"no":     {"Norwegian", "挪威语", "Norsk"},
	"oc":     {"Occitan", "奥克语", "Occitan"},
	"om":     {"Oromo", "奥罗莫语", "Afaan Oromo"},
	"or":     {"Oriya", "奥里亚语", "ଓଡ଼ିଆ"},
	"pa":     {"Punjabi", "旁遮普语", "ਪੰਜਾਬੀ"},
	"pl":     {"Polish", "波兰语", "Polski"},
	"ps":     {"Pashto", "普什图语", "پښتو"},
	"pt":     {"Portuguese", "葡萄牙语", "Português"},
	"pt-BR":  {"Portuguese (Brazil)", "葡萄牙语（巴西）", "Português (Brasil)"},
	"pt-PT":  {"Portuguese (Portugal)", "葡萄牙语（葡萄牙）", "Português (Portugal)"},
	"qu":     {"Quechua", "克丘亚语", "Quechua"},
	"rm":     {"Romansh", "罗曼什语", "Rumantsch"},
	"ro":     {"Romanian", "罗马尼亚语", "Română"},
	"ru":     {"Russian", "俄语", "Русский"},
	"ru-RU":  {"Russian (Russia)", "俄语（俄罗斯）", "Русский (Россия)"},
	"sd":     {"Sindhi", "信德语", "سنڌي"},
	"sh":     {"Serbo-Croatian", "塞尔维亚-克罗地亚语", "Srpskohrvatski"},
	"si":     {"Sinhalese", "僧伽罗语", "සිංහල"},
	"sk":     {"Slovak", "斯洛伐克语", "Slovenčina"},
	"sl":     {"Slovenian", "斯洛文尼亚语", "Slovenščina"},
	"sn":     {"Shona", "绍纳语", "ChiShona"},
	"so":     {"Somali", "索马里语", "Soomaali"},
	"sq":     {"Albanian", "阿尔巴尼亚语", "Shqip"},
	"sr":     {"Serbian", "塞尔维亚语", "Српски"},
	"st":     {"Sesotho", "塞索托语", "Sesotho"},
	"su":     {"Sundanese", "巽他语", "Basa Sunda"},
	"sv":     {"Swedish", "瑞典语", "Svenska"},
	"sv-SE":  {"Swedish (Sweden)", "瑞典语（瑞典）", "Svenska (Sverige)"},
	"sw":     {"Swahili", "斯瓦希里语", "Kiswahili"},
	"ta":     {"Tamil", "泰米尔语", "தமிழ்"},
	"te":     {"Telugu", "泰卢固语", "తెలుగు"},
	"tg":     {"Tajik", "塔吉克语", "Тоҷикӣ"},
	"th":     {"Thai", "泰语", "ไทย"},
	"th-TH":  {"Thai (Thailand)", "泰语（泰国）", "ไทย (ประเทศไทย)"},
	"ti":     {"Tigrinya", "提格雷尼亚语", "ትግርኛ"},
	"tk":     {"Turkmen", "土库曼语", "Türkmençe"},
	"to":     {"Tonga", "汤加语", "Lea faka-Tonga"},
	"tr":     {"Turkish", "土耳其语", "Türkçe"},
	"tr-TR":  {"Turkish (Turkey)", "土耳其语（土耳其）", "Türkçe (Türkiye)"},
	"tt":     {"Tatar", "鞑靼语", "Татарча"},
	"tw":     {"Twi", "契维语", "Twi"},
	"ug":     {"Uighur", "维吾尔语", "ئۇيغۇرچە"},
	"uk":     {"Ukrainian", "乌克兰语", "Українська"},
	"ur":     {"Urdu", "乌尔都语", "اردو"},
	"uz":     {"Uzbek", "乌兹别克语", "Oʻzbekcha"},
	"vi":     {"Vietnamese", "越南语", "Tiếng Việt"},
	"vi-VN":  {"Vietnamese (Vietnam)", "越南语（越南）", "Tiếng Việt (Việt Nam)"},
	"xh":     {"Xhosa", "科萨语", "IsiXhosa"},
	"yi":     {"Yiddish", "意第绪语", "ייִדיש"},
	"yo":     {"Yoruba", "约鲁巴语", "Yorùbá"},
	"zh":     {"Chinese", "中文", "中文"},
	"zh-CN":  {"Chinese (Simplified)", "中文（简体）", "中文（简体）"},
	"zh-TW":  {"Chinese (Traditional)", "中文（繁体）", "中文（繁体）"},
	"zh-HK":  {"Chinese (Hong Kong)", "中文（香港）", "中文（香港）"},
	"zu":     {"Zulu", "祖鲁语", "IsiZulu"},
	"ab":     {"Abkhazian", "阿布哈兹语", "Абхазский"},
	"aa":     {"Afar", "阿法尔语", "Afaraf"},
	"ak":     {"Akan", "阿坎语", "Akan"},
	"an":     {"Aragonese", "阿拉贡语", "Aragonés"},
	"as":     {"Assamese", "阿萨姆语", "অসমীয়া"},
	"av":     {"Avaric", "阿瓦尔语", "Аварский"},
	"ae":     {"Avestan", "阿维斯陀语", "Avesta"},
	"ay":     {"Aymara", "艾马拉语", "Aymar"},
	"ba":     {"Bashkir", "巴什基尔语", "Башҡорт"},
	"bm":     {"Bambara", "班巴拉语", "Bamanankan"},
	"bi":     {"Bislama", "比斯拉马语", "Bislama"},
	"bo":     {"Tibetan", "藏语", "བོད་སྐད།"},
	"bv":     {"Bouvet Island", "布维岛语（挪威语）", "Norsk (Bouvetøya)"},
	"cb":     {"Cebuano", "宿务语", "Cebuano"},
	"ce":     {"Chechen", "车臣语", "Нохчийн"},
	"ch":     {"Chamorro", "查莫罗语", "Chamoru"},
	"cu":     {"Church Slavic", "教会斯拉夫语", "Церковнославянский"},
	"cv":     {"Chuvash", "楚瓦什语", "Чăваш"},
	"dw":     {"Divehi", "迪维希语", "ދިވެހި"},
	"dz":     {"Dzongkha", "不丹语（宗卡语）", "རྫོང་ཁ"},
	"ee":     {"Ewe", "埃维语", "Eʋe"},
	"eg":     {"Egyptian", "古埃及语", "مصرية القديمة"},
	"eh":     {"Estonian", "爱沙尼亚语（旧称）", "Eesti"},
	"er":     {"Erzya", "埃尔齐亚语", "Эрзянь"},
	"ff":     {"Fulah", "富拉语", "Fulfulde"},
	"fj":     {"Fijian", "斐济语", "Vosa Vakaviti"},
	"fk":     {"Falkland Islands", "福克兰群岛语（英语）", "English (Falkland Islands)"},
	"fm":     {"Federated States of Micronesia", "密克罗尼西亚语", "Chuukese"},
	"gb":     {"English (UK)", "英语（英国）", "English (UK)"},
	"ge":     {"Georgian", "格鲁吉亚语", "ქართული"},
	"gf":     {"French (Guiana)", "法语（法属圭亚那）", "Français (Guyane française)"},
	"gg":     {"English (Guernsey)", "英语（根西岛）", "English (Guernsey)"},
	"gh":     {"Akan", "阿坎语（加纳）", "Akan (Ghana)"},
	"gi":     {"English (Gibraltar)", "英语（直布罗陀）", "English (Gibraltar)"},
	"gm":     {"Wolof", "沃洛夫语（冈比亚）", "Wolof (Gambia)"},
	"gp":     {"French (Guadeloupe)", "法语（瓜德罗普）", "Français (Guadeloupe)"},
	"gq":     {"French (Equatorial Guinea)", "法语（赤道几内亚）", "Français (Guinée équatoriale)"},
	"gr":     {"Greek (Greece)", "希腊语（希腊）", "Ελληνικά (Ελλάδα)"},
	"gs":     {"English (South Georgia)", "英语（南乔治亚岛）", "English (South Georgia)"},
	"gv":     {"Manx", "马恩岛语", "Gaelg"},
	"hb":     {"Hebrew", "希伯来语（旧称）", "עברית"},
	"hd":     {"Hindi", "印地语（方言）", "हिन्दी"},
	"hg":     {"Hiligaynon", "希利盖农语", "Hiligaynon"},
	"ho":     {"Hiri Motu", "希里莫图语", "Hiri Motu"},
	"ht":     {"Haitian Creole", "海地克里奥尔语", "Kreyòl ayisyen"},
	"hz":     {"Herero", "赫雷罗语", "Otjiherero"},
}

// GetLangInfoByCode 通过语言码获取完整信息（英文名称+中文名称+母语名称）
// 支持大小写不敏感、地区变体兼容
func GetLangInfoByCode(code string) (LangInfo, bool) {
	// 统一格式：语言码小写，地区码大写（如 zh-cn → zh-CN）
	code = strings.ToLower(code)
	parts := strings.Split(code, "-")
	if len(parts) == 2 {
		code = parts[0] + "-" + strings.ToUpper(parts[1])
	}

	// 精确匹配语言码
	info, exists := langCodeMap[code]
	if exists {
		return info, true
	}

	// 模糊匹配：无地区码时，匹配基础语言（如 zh → zh-CN 的基础信息）
	baseCode := parts[0]
	baseInfo, baseExists := langCodeMap[baseCode]
	if baseExists {
		return baseInfo, true
	}

	return LangInfo{}, false
}
